<template>
  <lc-st
    ref="st"
    v-bind="params"
    :data="data"
    :expand="true"
    :expandChange="change"
    :onloadChildren="onloadChildren"
    :pages="{ hideOnSinglePage: true }"
  >
    <template v-slot:expand="res">
      <lc-tree-st
        v-if="url"
        ref="tree"
        v-bind="params"
        :operator="'none'"
        :expand="true"
        :parent="res.row"
        :noPage="noPage"
        :data="url"
      />
    </template>
  </lc-st>
</template>
<script setup lang="ts" name="lc-tree-st">
import { reactive, ref, toRaw } from "vue";
import { NzSafeAny } from "../sf/type";
import { ITreeTableOption, STExposeComponent } from "../st/interface";
const props = defineProps<ITreeTableOption>();
const { parent, noPage, ...args } = toRaw(props);
const url = ref(null);
const params = reactive(args);
const tree = ref<{ tree: STExposeComponent; treeChild: STExposeComponent }>(
  null
);
const st = ref<STExposeComponent>(null);
const change = (a: Record<string, NzSafeAny>, index: number) => {
  url.value = props.expandChange?.(a, index);
};

const onloadChildren = (url: string) => {
  return parent ? url.includes(parent?.id) : true;
};

defineExpose({
  tree: st,
  treeChild: tree.value?.tree
});
</script>
../st/interfaces ../sf/types
